package cn.softeem.tushu.service.Impl;

import cn.softeem.tushu.Dao.Impl.OrderDaoImpl;
import cn.softeem.tushu.Dao.OrderDao;
import cn.softeem.tushu.po.Order;
import cn.softeem.tushu.service.OrderService;
import cn.softeem.tushu.utils.DruidPool;
import cn.softeem.tushu.utils.PageBean;

import java.sql.SQLException;

public class OrderServiceImpl implements OrderService {
    OrderDao orderDao=new OrderDaoImpl();
    @Override
    public void save(Order order) {
        try {
            DruidPool.beginTransaction();
            orderDao.save(order);
            DruidPool.commitTransaction();
        } catch (SQLException e) {
            try {
                DruidPool.rollTransaction();
            } catch (SQLException e1) {
                throw new RuntimeException(e1);
            }
            throw new RuntimeException(e);
        }
    }

    @Override
    public PageBean<Order> getOrderList(String uid, int pageNow) {
        try {
            return orderDao.getOrderList(uid,pageNow);
        } catch (SQLException throwables) {
            throw  new RuntimeException("查询分类失败");
        }
    }

    @Override
    public Order desc(String oid) {
        try {
            return orderDao.desc(oid);
        } catch (SQLException throwables) {
            throw  new RuntimeException("查询分类失败");
        }
    }

    @Override
    public void cancel(String oid) {
        try {
            DruidPool.beginTransaction();
            orderDao.cancel(oid);
            DruidPool.commitTransaction();
        } catch (SQLException e) {
            try {
                DruidPool.rollTransaction();
            } catch (SQLException e1) {
                throw new RuntimeException(e1);
            }
            throw new RuntimeException(e);
        }
    }

    @Override
    public void confirm(String oid) {
        try {
            DruidPool.beginTransaction();
            orderDao.confirm(oid);
            DruidPool.commitTransaction();
        } catch (SQLException e) {
            try {
                DruidPool.rollTransaction();
            } catch (SQLException e1) {
                throw new RuntimeException(e1);
            }
            throw new RuntimeException(e);
        }
    }
    @Override
    public void pay(String oid) {
        try {
            DruidPool.beginTransaction();
            orderDao.pay(oid);
            DruidPool.commitTransaction();
        } catch (SQLException e) {
            try {
                DruidPool.rollTransaction();
            } catch (SQLException e1) {
                throw new RuntimeException(e1);
            }
            throw new RuntimeException(e);
        }
    }
}
